package com.demo;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @BelongsProject: study
 * @BelongsPackage: com.demo
 * @Author: zhangzhanheng
 * @CreateTime: 2022-09-08  10:19
 * @Description: TODO
 * @Version: 1.0
 */
public class IntForUseThreadDemo {
    private static AtomicInteger a = new AtomicInteger(0);
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 1000000000; i++) {
                    a.addAndGet(1);
                }
                System.out.println(Thread.currentThread().getName()+"执行结束");
            }
        });
        Thread t2 = new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 1000000000; i++) {
                    a.addAndGet(1);
                }
                System.out.println(Thread.currentThread().getName()+"执行结束");
            }
        });
        t1.start();
        t2.start();
        Thread.sleep(1000);
        System.out.println("num: --------" + a);

    }
}
